//
//  MPInputCell.m
//  MarkPlatform
//
//  Created by xiao6 on 2017/12/25.
//  Copyright © 2017年 AT. All rights reserved.
//

#import "MPInputCell.h"

@interface MPInputCell()

@property (weak, nonatomic) IBOutlet UILabel *titleLabel;
@property (weak, nonatomic) IBOutlet UITextField *textField;

@end

@implementation MPInputCell

+ (CGFloat)cellHeight {
    return 50.f;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    
    @weakify(self)
    [self.textField notifyChange:^NSInteger(UITextField *textField, NSString *text) {
        @strongify(self)
        self.model.inputText = text;
        dispatch_async(dispatch_get_main_queue(), ^{
            @strongify(self)
            !self.notifyInputChange ?: self.notifyInputChange(self);
        });
        return self.model.maxLength;
    }];
}

- (void)setModel:(MPInputCellModel *)model {
    _model = model;
    self.titleLabel.text = _model.title;
    self.textField.text = _model.inputText;
    self.textField.placeholder = _model.placeholder;
    self.textField.keyboardType = _model.keyboardType;
}
@end
